package com.moji.controller.api;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.moji.common.base.ApiResult;
import com.moji.entity.MjOrder;
import com.moji.entity.MjProductPurchase;
import com.moji.entity.MjProductPurchasePrice;
import com.moji.entity.dto.AddOrderDto;
import com.moji.entity.dto.MjProductPurchasePriceCommon;
import com.moji.entity.dto.MjProductPurchasePriceCommon1;
import com.moji.entity.vo.MjProductPurchasePrice1Vo;
import com.moji.entity.vo.MjProductPurchasePriceVo;
import com.moji.entity.vo.PurchasePriceVo;
import com.moji.service.MjOrderService;
import com.moji.service.MjProductPurchasePriceService;
import com.moji.service.MjProductPurchaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 产品选购价格表 前端控制器
 * </p>
 *
 * @author ccl
 * @since 2024-10-14
 */
@RestController
@RequestMapping("web/auth/mjProductPurchase_price")
@Api(tags = "产品选购价格web相关接口(控制中心)", value = "产品选购价格web相关接口(控制中心)")
public class MjProductPurchasePriceController {
    @Resource
    private MjProductPurchasePriceService mjProductPurchasePriceService;
    @Resource
    private MjProductPurchaseService mjProductPurchaseService;

    @PostMapping("/price")
    @ApiOperation(value = "获取价格", response = Boolean.class)
    public ApiResult<MjProductPurchasePriceVo> add(@Validated @RequestBody MjProductPurchasePriceCommon mjProductPurchasePriceCommon) {
        MjProductPurchasePrice mjProductPurchasePrice = mjProductPurchasePriceService.getOne(new LambdaQueryWrapper<MjProductPurchasePrice>()
                .eq(MjProductPurchasePrice::getRegionCode, mjProductPurchasePriceCommon.getRegionCode())
                .eq(MjProductPurchasePrice::getEndpointCode, mjProductPurchasePriceCommon.getEndpointCode())
                .eq(MjProductPurchasePrice::getAccesstypeCode, mjProductPurchasePriceCommon.getAccesstypeCode()));
        MjProductPurchasePriceVo mjProductPurchasePriceVo = new MjProductPurchasePriceVo();
        if (mjProductPurchasePrice != null) {
            BeanUtil.copyProperties(mjProductPurchasePrice, mjProductPurchasePriceVo);
            List<PurchasePriceVo> purchasePriceVos = new ArrayList<>();
            PurchasePriceVo priceVo9 = new PurchasePriceVo();
            MjProductPurchase mjProductPurchase8 = mjProductPurchaseService.getOne(new LambdaQueryWrapper<MjProductPurchase>()
                    .eq(MjProductPurchase::getSubTitleCode, "T1W"));
            priceVo9.setId(mjProductPurchase8.getId() + "");
            priceVo9.setContent(mjProductPurchase8.getContent());
            priceVo9.setPicture(mjProductPurchase8.getPicture());
            priceVo9.setCode("T1W");
            priceVo9.setName(mjProductPurchase8.getSubTitle());
            priceVo9.setValue("0");
            priceVo9.setStatus("1");
            purchasePriceVos.add(priceVo9);
            PurchasePriceVo priceVo1 = new PurchasePriceVo();
            MjProductPurchase mjProductPurchase = mjProductPurchaseService.getOne(new LambdaQueryWrapper<MjProductPurchase>()
                    .eq(MjProductPurchase::getSubTitleCode, "D5W"));
            priceVo1.setId(mjProductPurchase.getId() + "");
            priceVo1.setContent(mjProductPurchase.getContent());
            priceVo1.setPicture(mjProductPurchase.getPicture());
            priceVo1.setCode("D5W");
            priceVo1.setName("5万次/日");
            priceVo1.setValue(mjProductPurchasePrice.getD5wPrice());
            priceVo1.setStatus(mjProductPurchasePrice.getD5Status());
            purchasePriceVos.add(priceVo1);
            PurchasePriceVo priceVo2 = new PurchasePriceVo();

            MjProductPurchase mjProductPurchase1 = mjProductPurchaseService.getOne(new LambdaQueryWrapper<MjProductPurchase>()
                    .eq(MjProductPurchase::getSubTitleCode, "D10W"));
            priceVo2.setId(mjProductPurchase1.getId() + "");
            priceVo2.setContent(mjProductPurchase1.getContent());
            priceVo2.setPicture(mjProductPurchase1.getPicture());

            priceVo2.setCode("D10W");
            priceVo2.setName("10万次/日");
            priceVo2.setValue(mjProductPurchasePrice.getD10wPrice());
            priceVo2.setStatus(mjProductPurchasePrice.getD10Status());
            purchasePriceVos.add(priceVo2);
            PurchasePriceVo priceVo3 = new PurchasePriceVo();
            MjProductPurchase mjProductPurchase2 = mjProductPurchaseService.getOne(new LambdaQueryWrapper<MjProductPurchase>()
                    .eq(MjProductPurchase::getSubTitleCode, "D50W"));
            priceVo3.setId(mjProductPurchase2.getId() + "");
            priceVo3.setContent(mjProductPurchase2.getContent());
            priceVo3.setPicture(mjProductPurchase2.getPicture());
            priceVo3.setCode("D50W");
            priceVo3.setName("50万次/日");
            priceVo3.setValue(mjProductPurchasePrice.getD50wPrice());
            priceVo3.setStatus(mjProductPurchasePrice.getD50Status());
            purchasePriceVos.add(priceVo3);
            PurchasePriceVo priceVo4 = new PurchasePriceVo();
            MjProductPurchase mjProductPurchase3 = mjProductPurchaseService.getOne(new LambdaQueryWrapper<MjProductPurchase>()
                    .eq(MjProductPurchase::getSubTitleCode, "D100W"));
            priceVo4.setId(mjProductPurchase3.getId() + "");
            priceVo4.setContent(mjProductPurchase3.getContent());
            priceVo4.setPicture(mjProductPurchase3.getPicture());
            priceVo4.setCode("D100W");
            priceVo4.setName("100万次/日");
            priceVo4.setValue(mjProductPurchasePrice.getD100wPrice());
            priceVo4.setStatus(mjProductPurchasePrice.getD100Status());
            purchasePriceVos.add(priceVo4);
            PurchasePriceVo priceVo5 = new PurchasePriceVo();
            MjProductPurchase mjProductPurchase4 = mjProductPurchaseService.getOne(new LambdaQueryWrapper<MjProductPurchase>()
                    .eq(MjProductPurchase::getSubTitleCode, "D150W"));
            priceVo5.setId(mjProductPurchase4.getId() + "");
            priceVo5.setContent(mjProductPurchase4.getContent());
            priceVo5.setPicture(mjProductPurchase4.getPicture());
            priceVo5.setCode("D150W");
            priceVo5.setName("150万次/日");
            priceVo5.setValue(mjProductPurchasePrice.getD150wPrice());
            priceVo5.setStatus(mjProductPurchasePrice.getD150Status());
            purchasePriceVos.add(priceVo5);
            PurchasePriceVo priceVo6 = new PurchasePriceVo();
            MjProductPurchase mjProductPurchase5 = mjProductPurchaseService.getOne(new LambdaQueryWrapper<MjProductPurchase>()
                    .eq(MjProductPurchase::getSubTitleCode, "D200W"));
            priceVo6.setId(mjProductPurchase5.getId() + "");
            priceVo6.setContent(mjProductPurchase5.getContent());
            priceVo6.setPicture(mjProductPurchase5.getPicture());
            priceVo6.setCode("D200W");
            priceVo6.setName("200万次/日");
            priceVo6.setValue(mjProductPurchasePrice.getD200wPrice());
            priceVo6.setStatus(mjProductPurchasePrice.getD200Status());
            purchasePriceVos.add(priceVo6);

            PurchasePriceVo priceVo7 = new PurchasePriceVo();
            MjProductPurchase mjProductPurchase6 = mjProductPurchaseService.getOne(new LambdaQueryWrapper<MjProductPurchase>()
                    .eq(MjProductPurchase::getSubTitleCode, "D500W"));
            priceVo7.setId(mjProductPurchase6.getId() + "");
            priceVo7.setContent(mjProductPurchase6.getContent());
            priceVo7.setPicture(mjProductPurchase6.getPicture());
            priceVo7.setCode("D500W");
            priceVo7.setName("500万次/日");
            priceVo7.setValue(mjProductPurchasePrice.getD500wPrice());
            priceVo7.setStatus(mjProductPurchasePrice.getD500Status());
            purchasePriceVos.add(priceVo7);

            PurchasePriceVo priceVo8 = new PurchasePriceVo();
            MjProductPurchase mjProductPurchase7 = mjProductPurchaseService.getOne(new LambdaQueryWrapper<MjProductPurchase>()
                    .eq(MjProductPurchase::getSubTitleCode, "D1000W"));
            priceVo8.setId(mjProductPurchase7.getId() + "");
            priceVo8.setContent(mjProductPurchase7.getContent());
            priceVo8.setPicture(mjProductPurchase7.getPicture());
            priceVo8.setCode("D1000W");
            priceVo8.setName("1000万次/日");
            priceVo8.setValue(mjProductPurchasePrice.getD1000wPrice());
            priceVo8.setStatus(mjProductPurchasePrice.getD1000Status());
            purchasePriceVos.add(priceVo8);


            mjProductPurchasePriceVo.setPurchasePriceVoList(purchasePriceVos);
            return ApiResult.ok(mjProductPurchasePriceVo);
        }
        return ApiResult.failed("查询失败");
    }

    @PostMapping("/status")
    @ApiOperation(value = "获取状态", response = Boolean.class)
    public ApiResult<List<MjProductPurchasePrice1Vo>> status(@Validated @RequestBody MjProductPurchasePriceCommon1 mjProductPurchasePriceCommon) {
        List<MjProductPurchasePrice> list = mjProductPurchasePriceService.list(new LambdaQueryWrapper<MjProductPurchasePrice>()
                .eq(MjProductPurchasePrice::getRegionCode, mjProductPurchasePriceCommon.getRegionCode())
                .eq(MjProductPurchasePrice::getAccesstypeCode, mjProductPurchasePriceCommon.getAccesstypeCode()));
        List<MjProductPurchasePrice1Vo> list1 = new ArrayList<>();
        if (list != null) {
            for (int i = 0; i < list.size(); i++) {
                MjProductPurchasePrice1Vo mjProductPurchasePrice1Vo = new MjProductPurchasePrice1Vo();
                mjProductPurchasePrice1Vo.setEndpointCode(list.get(i).getEndpointCode());
                mjProductPurchasePrice1Vo.setEndpointName(list.get(i).getEndpointName());
                mjProductPurchasePrice1Vo.setStatus(list.get(i).getStatus());
                LambdaQueryWrapper<MjProductPurchase> eq = new LambdaQueryWrapper<MjProductPurchase>()
                        .eq(MjProductPurchase::getSubTitleCode, list.get(i).getEndpointCode());
                MjProductPurchase one = mjProductPurchaseService.getOne(eq);
                if (one != null) {
                    mjProductPurchasePrice1Vo.setId(one.getId());
                    mjProductPurchasePrice1Vo.setContent(one.getContent());
                    mjProductPurchasePrice1Vo.setPicture(one.getPicture());
                }

                list1.add(mjProductPurchasePrice1Vo);
            }
        }
        return ApiResult.ok(list1);
    }
}

